home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog3.arj / UEVAL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  2.1 KB  |  75 lines

  1. {******************************************************************}
  2. {                                                                  }
  3. {     Mancala                                                      }
  4. {     Turbo Pascal for Windows                                     }
  5. {     Copyright (c) 1991 by Swan Software. All rights reserved.    }
  6. {                                                                  }
  7. {******************************************************************}
  8.  
  9. { ueval.pas -- Move evaluator for Mancala }
  10.  
  11. unit UEval;
  12.  
  13. interface
  14.  
  15. uses UGlobals;
  16.  
  17. function BoardValue(var Position: BoardRec; Level: Integer): Integer;
  18.  
  19.  
  20. implementation
  21.  
  22.  
  23. {- Return evaluation for this game board position. }
  24.  
  25. function BoardValue(var Position: BoardRec; Level: Integer): Integer;
  26. var
  27.   I, Score: Integer;
  28. begin
  29.   with Position do
  30.   begin
  31.  
  32. {- Return maximum score for win or lowest score for loss. Return
  33. slightly higher scores for shallower levels to encourage the computer
  34. to win as early as possible. }
  35.  
  36.     if Gameboard[CompKalah] >= PebblesDiv2 then
  37.     begin
  38.       Win := true;
  39.       WinningSide := computer;
  40.       BoardValue := 255 - Level;
  41.     end else if Gameboard[HumanKalah] >= PebblesDiv2 then
  42.     begin
  43.       Win := true;
  44.       WinningSide := human;
  45.       BoardValue := Level - 255;
  46.     end else
  47.     begin
  48.       Win := false;
  49.  
  50. {- Initial score is two times the difference between the computer
  51. and human kalahs }
  52.  
  53.       Score := 2 * (Gameboard[CompKalah] - Gameboard[HumanKalah]);
  54.  
  55. {- Subtract one point for each human pebble and add one point for
  56. each computer pebble }
  57.  
  58.       for I := HumanFirstCup to HumanLastCup do
  59.         Score := Score - Gameboard[I];
  60.       for I := CompFirstCup to CompLastCup do
  61.         Score := Score + Gameboard[I];
  62.       Boardvalue := Score;  { Assign function result }
  63.     end;
  64.   end;
  65. end;
  66.  
  67.  
  68. end.
  69.  
  70.  
  71. { ----------------------------------------------------------------
  72.   Copyright (c) 1991 by Swan Software. All rights reserved.
  73.   Revision 1.00    Date: 8/21/1991
  74.   ---------------------------------------------------------------- }
  75.